home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / blankery / blanker / source / blankers / life / life.c < prev    next >
C/C++ Source or Header  |  1993-07-31  |  7KB  |  246 lines

  1. /*
  2.  *  Source machine generated by GadToolsBox V2.0b
  3.  *  which is (c) Copyright 1991-1993 Jaba Development
  4.  *
  5.  *  GUI Designed by : Michael D. Bayne
  6.  */
  7.  
  8. #include <exec/types.h>
  9. #include <intuition/intuition.h>
  10. #include <intuition/classes.h>
  11. #include <intuition/classusr.h>
  12. #include <intuition/imageclass.h>
  13. #include <intuition/gadgetclass.h>
  14. #include <libraries/gadtools.h>
  15. #include <graphics/displayinfo.h>
  16. #include <graphics/gfxbase.h>
  17. #include <clib/exec_protos.h>
  18. #include <clib/intuition_protos.h>
  19. #include <clib/gadtools_protos.h>
  20. #include <clib/graphics_protos.h>
  21. #include <clib/utility_protos.h>
  22. #include <string.h>
  23. #include <clib/diskfont_protos.h>
  24.  
  25. #include "Life.h"
  26.  
  27. struct Screen         *Scr = NULL;
  28. UBYTE                 *PubScreenName = "Workbench";
  29. APTR                   VisualInfo = NULL;
  30. struct Window         *LifeWnd = NULL;
  31. struct Gadget         *LifeGList = NULL;
  32. struct IntuiMessage    LifeMsg;
  33. struct Gadget         *LifeGadgets[6];
  34. UWORD                  LifeLeft = 0;
  35. UWORD                  LifeTop = 12;
  36. UWORD                  LifeWidth = 240;
  37. UWORD                  LifeHeight = 59;
  38. UBYTE                 *LifeWdt = (UBYTE *)"Life Prefs";
  39. struct TextAttr       *Font, Attr;
  40. UWORD                  FontX, FontY;
  41. UWORD                  OffX, OffY;
  42. struct TextFont       *LifeFont = NULL;
  43.  
  44. UWORD LifeGTypes[] = {
  45.     SLIDER_KIND,
  46.     BUTTON_KIND,
  47.     BUTTON_KIND,
  48.     SLIDER_KIND,
  49.     SLIDER_KIND,
  50.     BUTTON_KIND
  51. };
  52.  
  53. struct NewGadget LifeNGad[] = {
  54.     82, 2, 119, 13, (UBYTE *)"_Size", NULL, GD_BSIZE, PLACETEXT_LEFT, NULL, (APTR)BSIZEClicked,
  55.     8, 45, 66, 12, (UBYTE *)"_Ok", NULL, GD_OK, PLACETEXT_IN, NULL, (APTR)OKClicked,
  56.     167, 45, 66, 12, (UBYTE *)"_Cancel", NULL, GD_CANCEL, PLACETEXT_IN, NULL, (APTR)CANCELClicked,
  57.     82, 17, 120, 12, (UBYTE *)"_Generations", NULL, GD_GENS, PLACETEXT_LEFT, NULL, (APTR)GENSClicked,
  58.     82, 31, 120, 12, (UBYTE *)"_Density", NULL, GD_DENSE, PLACETEXT_LEFT, NULL, (APTR)DENSEClicked,
  59.     87, 45, 66, 12, (UBYTE *)"_Test", NULL, GD_TEST, PLACETEXT_IN, NULL, (APTR)TESTClicked
  60. };
  61.  
  62. ULONG LifeGTags[] = {
  63.     (GTSL_Min), 5, (GTSL_Max), 40, (GTSL_Level), 20, (GTSL_MaxLevelLen), 4, (GTSL_LevelFormat), (ULONG)"%3ld", (GTSL_LevelPlace), (PLACETEXT_RIGHT), (PGA_Freedom), LORIENT_HORIZ, (GA_Immediate), TRUE, (GA_RelVerify), TRUE, (GT_Underscore), '_', (TAG_DONE),
  64.     (GT_Underscore), '_', (TAG_DONE),
  65.     (GT_Underscore), '_', (TAG_DONE),
  66.     (GTSL_Min), 5, (GTSL_Max), 999, (GTSL_Level), 150, (GTSL_MaxLevelLen), 4, (GTSL_LevelFormat), (ULONG)"%3ld", (GTSL_LevelPlace), (PLACETEXT_RIGHT), (PGA_Freedom), LORIENT_HORIZ, (GA_Immediate), TRUE, (GA_RelVerify), TRUE, (GT_Underscore), '_', (TAG_DONE),
  67.  
  68.  
  69.     (GTSL_Min), 1, (GTSL_Max), 99, (GTSL_Level), 16, (GTSL_MaxLevelLen), 4, (GTSL_LevelFormat), (ULONG)"%3ld", (GTSL_LevelPlace), (PLACETEXT_RIGHT), (PGA_Freedom), LORIENT_HORIZ, (GA_Immediate), TRUE, (GA_RelVerify), TRUE, (GT_Underscore), '_', (TAG_DONE),
  70.     (GT_Underscore), '_', (TAG_DONE)
  71. };
  72.  
  73. static UWORD ComputeX( UWORD value )
  74. {
  75.     return(( UWORD )((( FontX * value ) + 3 ) / 6 ));
  76. }
  77.  
  78. static UWORD ComputeY( UWORD value )
  79. {
  80.     return(( UWORD )((( FontY * value ) + 4 ) / 8 ));
  81. }
  82.  
  83. static void ComputeFont( UWORD width, UWORD height )
  84. {
  85.     Forbid();
  86.     Font = &Attr;
  87.     Font->ta_Name = (STRPTR)GfxBase->DefaultFont->tf_Message.mn_Node.ln_Name;
  88.     Font->ta_YSize = FontY = GfxBase->DefaultFont->tf_YSize;
  89.     FontX = GfxBase->DefaultFont->tf_XSize;
  90.     Permit();
  91.  
  92.     OffX = Scr->WBorLeft;
  93.     OffY = Scr->RastPort.TxHeight + Scr->WBorTop + 1;
  94.  
  95.     if ( width && height ) {
  96.         if (( ComputeX( width ) + OffX + Scr->WBorRight ) > Scr->Width )
  97.             goto UseTopaz;
  98.         if (( ComputeY( height ) + OffY + Scr->WBorBottom ) > Scr->Height )
  99.             goto UseTopaz;
  100.     }
  101.     return;
  102.  
  103. UseTopaz:
  104.     Font->ta_Name = (STRPTR)"topaz.font";
  105.     FontX = FontY = Font->ta_YSize = 8;
  106. }
  107.  
  108. int SetupScreen( void )
  109. {
  110.     if ( ! ( Scr = LockPubScreen( PubScreenName )))
  111.         return( 1L );
  112.  
  113.     ComputeFont( 0, 0 );
  114.  
  115.     if ( ! ( VisualInfo = GetVisualInfo( Scr, TAG_DONE )))
  116.         return( 2L );
  117.  
  118.     return( 0L );
  119. }
  120.  
  121. void CloseDownScreen( void )
  122. {
  123.     if ( VisualInfo ) {
  124.         FreeVisualInfo( VisualInfo );
  125.         VisualInfo = NULL;
  126.     }
  127.  
  128.     if ( Scr        ) {
  129.         UnlockPubScreen( NULL, Scr );
  130.         Scr = NULL;
  131.     }
  132. }
  133.  
  134. int HandleLifeIDCMP( void )
  135. {
  136.     struct IntuiMessage    *m;
  137.     int            (*func)();
  138.     BOOL            running = TRUE;
  139.  
  140.     while( m = GT_GetIMsg( LifeWnd->UserPort )) {
  141.  
  142.         CopyMem(( char * )m, ( char * )&LifeMsg, (long)sizeof( struct IntuiMessage ));
  143.  
  144.         GT_ReplyIMsg( m );
  145.  
  146.         switch ( LifeMsg.Class ) {
  147.  
  148.             case    IDCMP_REFRESHWINDOW:
  149.                 GT_BeginRefresh( LifeWnd );
  150.                 GT_EndRefresh( LifeWnd, TRUE );
  151.                 break;
  152.  
  153.             case    IDCMP_VANILLAKEY:
  154.                 running = LifeVanillaKey();
  155.                 break;
  156.  
  157.             case    IDCMP_GADGETUP:
  158.             case    IDCMP_GADGETDOWN:
  159.                 func = ( void * )(( struct Gadget * )LifeMsg.IAddress )->UserData;
  160.                 running = func();
  161.                 break;
  162.         }
  163.     }
  164.     return( running );
  165. }
  166.  
  167. int OpenLifeWindow( void )
  168. {
  169.     struct NewGadget    ng;
  170.     struct Gadget    *g;
  171.     UWORD        lc, tc;
  172.     UWORD        wleft, wtop, ww, wh;
  173.  
  174.     ComputeFont( LifeWidth, LifeHeight );
  175.  
  176.     ww = ComputeX( LifeWidth );
  177.     wh = ComputeY( LifeHeight );
  178.  
  179.     wleft = ( Scr->Width - ww )/2 - Scr->WBorRight;
  180.     wtop = ( Scr->Height - wh - Scr->WBorBottom*2 - Font->ta_YSize )/2;
  181.  
  182.     if ( ! ( LifeFont = OpenDiskFont( Font )))
  183.         return( 5L );
  184.  
  185.     if ( ! ( g = CreateContext( &LifeGList )))
  186.         return( 1L );
  187.  
  188.     for( lc = 0, tc = 0; lc < Life_CNT; lc++ ) {
  189.  
  190.         CopyMem((char * )&LifeNGad[ lc ], (char * )&ng, (long)sizeof( struct NewGadget ));
  191.  
  192.         ng.ng_VisualInfo = VisualInfo;
  193.         ng.ng_TextAttr   = Font;
  194.         ng.ng_LeftEdge   = OffX + ComputeX( ng.ng_LeftEdge );
  195.         ng.ng_TopEdge    = OffY + ComputeY( ng.ng_TopEdge );
  196.         ng.ng_Width      = ComputeX( ng.ng_Width );
  197.         ng.ng_Height     = ComputeY( ng.ng_Height);
  198.  
  199.         LifeGadgets[ lc ] = g = CreateGadgetA((ULONG)LifeGTypes[ lc ], g, &ng, ( struct TagItem * )&LifeGTags[ tc ] );
  200.  
  201.         while( LifeGTags[ tc ] ) tc += 2;
  202.         tc++;
  203.  
  204.         if ( NOT g )
  205.             return( 2L );
  206.     }
  207.  
  208.     if ( ! ( LifeWnd = OpenWindowTags( NULL,
  209.                 WA_Left,    wleft,
  210.                 WA_Top,        wtop,
  211.                 WA_Width,    ww + OffX + Scr->WBorRight,
  212.                 WA_Height,    wh + OffY + Scr->WBorBottom,
  213.                 WA_IDCMP,    SLIDERIDCMP|BUTTONIDCMP|IDCMP_VANILLAKEY|IDCMP_REFRESHWINDOW,
  214.                 WA_Flags,    WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_SMART_REFRESH|WFLG_ACTIVATE|WFLG_RMBTRAP,
  215.                 WA_Gadgets,    LifeGList,
  216.                 WA_Title,    LifeWdt,
  217.                 WA_ScreenTitle,    "Life Prefs",
  218.                 WA_AutoAdjust,    TRUE,
  219.                 WA_PubScreenFallBack,    TRUE,
  220.                 TAG_DONE )))
  221.     return( 4L );
  222.  
  223.     GT_RefreshWindow( LifeWnd, NULL );
  224.  
  225.     return( 0L );
  226. }
  227.  
  228. void CloseLifeWindow( void )
  229. {
  230.     if ( LifeWnd        ) {
  231.         CloseWindow( LifeWnd );
  232.         LifeWnd = NULL;
  233.     }
  234.  
  235.     if ( LifeGList      ) {
  236.         FreeGadgets( LifeGList );
  237.         LifeGList = NULL;
  238.     }
  239.  
  240.     if ( LifeFont ) {
  241.         CloseFont( LifeFont );
  242.         LifeFont = NULL;
  243.     }
  244. }
  245.  
  246.